#include <iostream>
#include <string>

using namespace std;

#define ROMAN_I             1
#define ROMAN_V             5
#define ROMAN_X             10
#define ROMAN_L             50
#define ROMAN_C             100
#define ROMAN_D             500
#define ROMAN_M             1000

class Solution {
public:
    string bitRoman(int, char, char, char);

    string intToRoman(int num);
};

string Solution::intToRoman(int num) {
    string res;
    // 1000
    res += bitRoman(num / 1000, 'M', '0', '0');
    num = num % 1000;
    // 100
    res += bitRoman(num / 100, 'C', 'D', 'M');
    num = num % 100;
    // 10
    res += bitRoman(num / 10, 'X', 'L', 'C');
    num = num % 10;
    // 1
    res += bitRoman(num, 'I', 'V', 'X');
    return res;
}

string Solution::bitRoman(int num, char one, char five, char ten) {
    string res;
    switch(num) {
        case 1:
        case 2:
        case 3:
            for (int i = 0; i < num; ++i) {
                res.push_back(one);
            }
            break;
        case 4:
            res.push_back(one);
        case 5:
            res.push_back(five);
            break;
        case 6:
        case 7:
        case 8:
            res.push_back(five);
            for (int i = 5; i < num; ++i) {
                res.push_back(one);
            }
            break;
        case 9:
            res.push_back(one);
            res.push_back(ten);
            break;
        default:
            break;
    }
    return res;
}

int main() {
//    std::cout << "Hello, World!" << std::endl;
    cout << Solution().intToRoman(1994);
    return 0;
}